﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DIS.Infrastructure.Entities.Repository;
using DIS.Infrastructure.Entities.Enum;
using DIS.Infrastructure.Entities.Cache;

namespace DIS.Infrastructure.Entities.Entity
{
    public class User : IAccessible<T_User,User>, ILogicEntity<T_User,User>
    {
        #region
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string RealName { get; set; }
        public Gender Gender { get; set; }
        public string Birthday { get; set; }
        public string QQ { get; set; }
        public string Phone { get; set; }
        public string Photo { get; set; }
        public DateTime CreateDate { get; set; }
        public bool IsActivate { get; set; }
        public string ProfessionName { get; set; }
        public string DepartMentName { get; set; }
        public UserRole SystemRole { get; set; }
        public string IdCardNo { get; set; }
        #endregion

         
        protected override void Covariant(T_User model)
        {
            this.Id = model.Id;
            this.UserName = model.UserName;
            this.Password = model.Password;
            this.RealName = model.RealName;
            this.Gender = model.Gender ? Enum.Gender.Male : Enum.Gender.Female;
            this.Birthday = model.Birthday;
            this.QQ = model.QQ;
            this.Phone = model.Phone;
            this.Photo = model.Photo;
            this.CreateDate = model.CreateDate;
            this.IsActivate = model.IsActivate;
            this.ProfessionName = model.ProfessionName;
            this.DepartMentName = model.DepartMentName;
            this.SystemRole = (UserRole)model.SystemRole;
            this.IdCardNo = model.IdCardNo;
        }
        protected override T_User Inverter(User model)
        {
            return new T_User()
            {
                Id=model.Id,
                Birthday = model.Birthday,
                Gender = model.Gender == Enum.Gender.Male,
                IsActivate = model.IsActivate,
                Password = model.Password,
                Phone = model.Phone,
                Photo = model.Photo,
                QQ = model.QQ,
                ProfessionName=model.ProfessionName,
                DepartMentName = model.DepartMentName,
                UserName = model.UserName,
                SystemRole = (int)model.SystemRole,
                CreateDate = model.CreateDate,
                IdCardNo = model.IdCardNo,
                RealName = model.RealName
            };
        }
        public User Set(T_User dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        /// <summary>
        /// 将启用缓存,通过username查找
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        //public override User Find(string key)
        //{
        //    return new UserCache().GetItem(key);
        //}
        //public override User PostDelete()
        //{
        //    new UserCache().RefreshItem(UserName);
        //    return base.PostDelete();
        //}
        //public override User PostModify()
        //{
        //    new UserCache().RefreshItem(UserName);
        //    return base.PostModify();
        //}
    }
}
